package com.kugou.internal.servlet;

import com.kugou.internal.SpyHelper;
import com.kugou.internal.service.SpyService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Alex on 2014/9/23
 */
public class SpyServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        String code = req.getParameter("code");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String mainClass = req.getParameter("mainClass");
        SpyService spyService = SpyHelper.getAppContext().getBean(SpyService.class);
        String response = spyService.doSpy(code, username, password, mainClass);
        resp.setCharacterEncoding("UTF-8");
        PrintWriter out = resp.getWriter();
        out.println(response);
        out.flush();
        out.close();
    }
}
